package com.yqz.common.handler;

import com.yqz.common.Result;
import com.yqz.common.exception.BussiException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常处理器
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    @ResponseBody
    public Object bussiExceptionHandler(BussiException exception){
        exception.printStackTrace();
        Integer code = exception.getCode();
        String msg = exception.getMsg();
        return new Result(code,msg);
    }

    @ExceptionHandler
    public String bussiExceptionHandler(Exception exception, HttpServletRequest req, HttpServletResponse resp){
        exception.printStackTrace();
        return null;
    }

}
